include(FetchContent)

execute_process(
        COMMAND git ls-remote --heads https://github.com/fltk/fltk master
        RESULT_VARIABLE fltk_primary_repo_ok
        OUTPUT_QUIET
        ERROR_QUIET
)

if (NOT fltk_primary_repo_ok EQUAL 0)
    message(STATUS "Primary fetch failed, falling back to Gitee mirror")
    set(fltk_repo https://gitee.com/dlmu-cone/fltk)
else ()
    set(fltk_repo https://github.com/fltk/fltk)
endif ()

FetchContent_Declare(
        fltk
        GIT_REPOSITORY ${fltk_repo}
        GIT_TAG master
        GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(fltk)
